package efr.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import efr.dao.PaginaDao;
import efr.dao.PoezieDao;
import efr.dao.impl.PaginaDaoImpl;
import efr.dao.impl.PoezieDaoImpl;
import efr.entity.Pagina;
import efr.util.EfrAdmUtil;

/**
 * Servlet implementation class Op4PaginaSubmitServlet
 */
public class Op4PaginaSubmitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(Op4PaginaSubmitServlet.class);
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Op4PaginaSubmitServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		if("Modifica".equals(request.getParameter("action"))){
			String id = request.getParameter("id");
			String pagina = request.getParameter("pagina");
			String data = request.getParameter("data");
			
			Pagina pag = new Pagina();
			pag.setId(Integer.valueOf(id));
			pag.setPagina(pagina);
			pag.setData(EfrAdmUtil.convertStringToDate(data, "yyyy-MM-dd HH:mm:ss.S"));
			
			PaginaDao paginaDao = new PaginaDaoImpl();
			paginaDao.updatePagina(pag);
		}
		if("Adauga".equals(request.getParameter("action"))){
			String pagina = request.getParameter("pagina");
			String data = request.getParameter("data");
			
			Pagina pag = new Pagina();
			pag.setPagina(pagina);
			pag.setData(EfrAdmUtil.convertStringToDate(data, "yyyy-MM-dd HH:mm:ss.S"));
			
			PaginaDao paginaDao = new PaginaDaoImpl();
			paginaDao.addPagina(pag);
			
		}
		
		RequestDispatcher view = request.getRequestDispatcher("/ListPagini.do");
		logger.debug("end doGet() ListPagini.do");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
